package com.example.api.mall.interceptor;

import com.example.api.mall.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @name: LoginInterceptorConfig
 * @description: 将拦截器注入spring
 * @author: xw.s
 * @date: 2021/6/1-9:40
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    /**
     * 拦截器的创建顺序就是执行顺序
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        // 添加路径时注意yml中的context-path配置的不起作用的，进入springboot，该路径已经失效，基于servlet的filter是可以拦截的
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**"); //拦截所有路径
//                .excludePathPatterns("/static/**") //排除静态资源
    }
}
